package com.woniuxy.thred.state;

/**
 * description: BlockedJoin01 <br>
 * date: 2022/2/5 6:31 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

/**
 * join:合并线程，插队线程
 */
public class BlockedJoin02 {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("爸爸让儿子买烟的故事");

        new Thread(new Father()).start();
    }
}

class Father extends Thread {
    @Override
    public void run() {
        System.out.println("想抽烟，发现烟没了");
        System.out.println("让儿子，取去买烟");
        Thread t = new Thread(new Son());
        t.start();
        try {
            t.join();//father被阻塞
            System.out.println("老爸拿到烟！");
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("老爸去找孩子");
        }
    }
}

class Son extends Thread {
    @Override
    public void run() {
        System.out.println("拿到老爸给的钱出去了.....");
        System.out.println("路边有个游戏厅，完了10秒");
        for (int i = 0; i < 10; i++) {
            System.out.println(i + "秒过去了。。。");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("去买烟去了");
        System.out.println("手拿一包烟回家");
    }
}